<?php

defined('_JEXEC') or die('Restricted access');
 

class DoskaViewMessages extends JViewLegacy
{
	
	protected $items;
	protected $pagination;
	protected $state;
	protected $sidebar;
	protected $listOrder;
	public $listDirn;
	public $filterForm;
	public $canDo;
	
	function display($tpl = null) 
	{
		
		$app = JFactory::getApplication();
		
		$this->sidebar = DoskaHelper::addSubmenu('messages');
		
		$this->items = $this->get('Items');//getItems
		
		$this->pagination = $this->get('Pagination');//getPagination
		
		$this->state			= $this->get('State');//getState
		
		$this->listOrder = $this->escape($this->state->get('list.ordering'));
		$this->listDirn = $this->escape($this->state->get('list.direction'));
	
		
		if (count($errors = $this->get('Errors'))) 
		{
			$app->enqueueMessage(implode('<br />', $errors), 'error');
			return false;
		}
		
		$this->filterForm = $this->get('FilterForm');//getFilterForm();
		$this->activeFilters = $this->get('ActiveFilters');//getActiveFilters();
		
		$this->canDo = Doskahelper::getActions();
		
		
		/*echo "<pre>";
		print_r($this->canDo);
		echo "</pre>";*/
		
		
		$this->addToolBar();
		$this->setDocument();
		
		parent::display($tpl);
	}
	
	protected function addToolBar() 
	{
		
		JToolBarHelper::title(JText::_('COM_DOSKA_MANAGER_MESSAGES'));
		
		
		if($this->canDo->get('core.create.messages') || $this->canDo->get('core.create')) {
			JToolBarHelper::addNew('message.add',JText::_('COM_DOSKA_MANEGER_MESSAGES_ADD'));
		}
		
		if ($this->canDo->get('core.edit') || $this->canDo->get('core.edit.own')) {
			JToolBarHelper::editList('message.edit');
		}
		
		
		
		if ($this->canDo->get('core.edit.state') || $this->canDo->get('core.edit.state.own')) { 
			JToolBarHelper::divider();
			JToolbarHelper::publish('messages.publish', 'JTOOLBAR_PUBLISH', true);
			JToolbarHelper::unpublish('messages.unpublish', 'JTOOLBAR_UNPUBLISH', true);
			JToolBarHelper::archiveList('messages.archive');
		    JToolBarHelper::trash('messages.trash');
		}
		
		
		
		if ($this->canDo->get('core.delete')) { 
			JToolBarHelper::deleteList('', 'messages.delete', 'JTOOLBAR_EMPTY_TRASH');
		}
		
		if ($this->canDo->get('core.admin')) { 
			JToolBarHelper::preferences('com_doska');
		}
		
	}	
		protected function setDocument() 
	{
		$document = JFactory::getDocument();
		$document->addStyleSheet(JUri::root(TRUE)."/media/com_doska/css/style.css");
	}
}